package org.mog.music.thread;

import dto.MusicInsertDTO;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import org.mog.music.service.IMusicService;

import javax.servlet.http.HttpServletRequest;

@Data
@AllArgsConstructor
@Builder
public class UpdateAndInsertThread extends Thread {
    private MusicInsertDTO musicInsertDTO;
    private IMusicService musicService;
    private HttpServletRequest request;
    private Long userId;


    @Override
    public void run() {
        if (musicInsertDTO != null) {
            String newUrl;
            try {
                newUrl = musicService.upload2FS(musicInsertDTO);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
            musicInsertDTO.setAudio(newUrl);

            musicService.insertMusic(musicInsertDTO, request, userId);
        }
        musicInsertDTO = null;
    }
}
